package neusoft.edu.cn.guanshangshiguang.model;

import neusoft.edu.cn.guanshangshiguang.Listener.Listener;
import neusoft.edu.cn.guanshangshiguang.bean.RegisterBean;
import neusoft.edu.cn.guanshangshiguang.common.Common;
import neusoft.edu.cn.guanshangshiguang.service.Service;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RegisterModel {

    private Retrofit retrofit;
    public RegisterModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://"+Common.IpAddress+"/literature_museum/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getResultList(String unumber,String uname,String password,String gender,String school,String student_id,
                              String department,final Listener registerListener){

        Service registerService = retrofit.create(Service.class);

        Call<RegisterBean> registerCall = registerService.getRegister(unumber,uname,password,gender,school,student_id,department);

        registerCall.enqueue(new Callback<RegisterBean>() {
                @Override
                public void onResponse(Call<RegisterBean> call, Response<RegisterBean> response) {
                    if(response!=null)
                        registerListener.onResponse(response.body());
                    else registerListener.onFail("获取登录信息失败");
                }

            @Override
            public void onFailure(Call<RegisterBean> call, Throwable t) {
                registerListener.onFail(t.toString());
            }
        });
    }
}
